local pianan = fk.CreateSkill{
  name = "lingling__pianan",
}

Fk:loadTranslationTable{
  ["lingling__pianan"] = "偏安",
  [":lingling__pianan"] = "当你每回合首次成为基本牌/锦囊牌的目标后，你可以令使用者摸一张牌，然后其本回合不能对你使用锦囊牌/基本牌。",

  ["#lingling__pianan-invoke"] = "偏安：你可以令 %dest 摸一张牌，其本回合不能对你使用%arg",
}

pianan:addEffect(fk.TargetConfirmed, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(pianan.name) and
      data.card.type ~= Card.TypeEquip and not data.from.dead and
      not table.contains(player:getTableMark("lingling__pianan-turn"), data.card.type) then
      player.room:addTableMark(player, "lingling__pianan-turn", data.card.type)
      local use_events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
        local use = e.data
        return use.card.type == data.card.type and table.contains(use.tos, player)
      end, Player.HistoryTurn)
      return #use_events == 1 and use_events[1].data.card == data.card
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = pianan.name,
      prompt = "#lingling__pianan-invoke::"..data.from.id..":"..(data.card.type == Card.TypeBasic and "trick" or "basic"),
    }) then
      event:setCostData(self, {tos = {data.from}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local type = data.card.type == Card.TypeBasic and "trick" or "basic"
    room:addTableMark(data.from, "lingling__pianan_"..type.."-turn", player.id)
    data.from:drawCards(1, pianan.name)
  end,
})

pianan:addEffect("prohibit", {
  is_prohibited = function (self, from, to, card)
    return to and card and
      table.contains(from:getTableMark("lingling__pianan_"..card:getTypeString().."-turn"), to.id)
  end,
})

return pianan
